package com.active.service.impl;

import com.active.bean.ActiveInfo;
import com.active.dao.ActiveInfoMapper;
import com.active.service.IActiveInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ActiveInfoServiceImpl implements IActiveInfoService{

    @Autowired
    private ActiveInfoMapper activeInfoDao;

    @Override
    @Transactional(readOnly = true)
    public ActiveInfo getActiveInfoById(Integer activeId) throws Exception {
        return activeInfoDao.selectByPrimaryKey(activeId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<ActiveInfo> getActiveInfosByListId(Integer activeListId) throws Exception {
        return activeInfoDao.selectByActiveListId(activeListId);
    }

    @Override
    public List<ActiveInfo> selectByUserAndActiveListId(Integer activeListId, int userId) throws Exception {
        return activeInfoDao.selectByUserAndActiveListId(activeListId,userId);
    }

    @Override
    @Transactional(readOnly = false)
    public int insertActiveInfo(ActiveInfo activeInfo) throws Exception {
        return activeInfoDao.insert(activeInfo);
    }

    @Override
    @Transactional(readOnly = false)
    public int updateActiveInfoById(ActiveInfo activeInfo) throws Exception {
        return activeInfoDao.updateByPrimaryKey(activeInfo);
    }

    @Override
    @Transactional(readOnly = false)
    public int deleteActiveInfoByActiveListId(Integer id) throws Exception {
        return activeInfoDao.deleteByActiveListId(id);
    }

    @Override
    @Transactional(readOnly = false)
    public int updateActiveInfoToStopByListId(Integer id) throws Exception{
        return activeInfoDao.updateStopMissionByListId(id);
    }

    @Override
    @Transactional(readOnly = true)
    public int checkMissionFinished(Integer activeListId) throws Exception{
        return activeInfoDao.checkMissionFinished(activeListId);
    }

    @Override
    @Transactional(readOnly = false)
    public int deleteByActiveListId(Integer activeListId) throws Exception {
        return deleteActiveInfoByActiveListId(activeListId);
    }
}
